package com.acargil.sudoku.model.structure;

import com.acargil.sudoku.model.exception.InvalidCellValueException;

public class StandardCell {

	public static final int[] VALUE_RANGE = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	public static final int EMPTY_VALUE = 0;

	private int value;
	private Coordinate coordinate;
	
	public StandardCell(Coordinate coordinate, int value) throws InvalidCellValueException {
		if (!isValueValid(value)) {
			throw new InvalidCellValueException("Cell value ["+value+"] is invalid.");
		}
		
		this.value = value;
		this.coordinate = coordinate;
	}

	public StandardCell(Coordinate coordinate) throws InvalidCellValueException {
		this(coordinate, EMPTY_VALUE);
	}

	public Coordinate getCoordinate() {
		return coordinate;
	}
	
	public void setCoordinate(Coordinate coordinate) {
		this.coordinate = coordinate;
	}
	
	public int getValue() {
		return value;
	}

	public void setValue(int value) throws InvalidCellValueException {
		if (!isValueValid(value)) {
			throw new InvalidCellValueException("Cell value ["+value+"] is invalid.");
		}
		
		this.value = value;
	}

	public boolean isEmpty() {
		return this.value == EMPTY_VALUE;
	}

	private boolean isValueValid(int value) {
		if (value >= 0 && value <= 9) {
			return true;
		}
		else {
			return false;
		}
	}
	
	
	@Override
	public String toString() {
		return value + "@" + coordinate.toString();
	}
	
	public static int[] getValueRange() {
		int[] valueRange = new int[VALUE_RANGE.length];
		for (int i = 0; i < VALUE_RANGE.length; i++) {
			valueRange[i] = VALUE_RANGE[i];
		}
		
		return valueRange;
	}
}
